BioBlend is a python libary for Galaxy toolkits. It enables high level developments for deploying and deleting cloud instances for Galaxy in python. Furthermore, it supports load and execute workflows on python in a simple format.
BioBlend: https://github.com/afgane/bioblend
An example for using BioBlend:
from bioblend.galaxy import GalaxyInstance
gi = GalaxyInstance('<Galaxy IP>', key='your API key')
libs = gi.libraries.get_libraries()
gi.workflows.show_workflow('workflow ID')
gi.workflows.run_workflow('workflow ID', input_dataset_map)
This tutorial shows how to use the BioBlend library with workflow examples so that python developers can use Galaxy tools on python and Ipython.
This step connects to a galaxy server using BioBlend. A server url and an api key are required to connect.
The server url is a location for the installed galaxy server and the api key is an identification of a user.
We have installed a galaxy on a local machine with ipython. So, the galaxy url should be on a local ip address and a default port number 8080, e.g. http://127.0.0.1:8080.
If you want to use a different galaxy server e.g. the public galaxy server hosted by Penn State University, use https://main.g2.bx.psu.edu/.
For the galaxy_api_key, a galaxy user needs to get the string from here: http://[galaxy_server]/user/api_keys?cntrller=user
It is like a password, so only logged in users can obtain the key. Here, I used the key d8699f27a08cc6f42a065e39955b6c47
for my account on the local galaxy server.
In [66]:
from bioblend.galaxy import GalaxyInstance
galaxy_url = "http://127.0.0.1:8080"
galaxy_api_key = "d8699f27a08cc6f42a065e39955b6c47"
gi = GalaxyInstance(url=galaxy_url, key=galaxy_api_key)
In [69]:
hl = gi.histories.get_histories()
hl
Out[69]:
Note.
Galaxy has analytical tools based on Python. Each one of them has an id. For example, CONVERTER_interval_to_bedstrict_0
The JSON Workflow file has section name "tool_id" for the id. e.g. https://gist.github.com/lee212/f1449352334a2268b849
In [14]:
workflows = gi.workflows.get_workflows()
workflows
Out[14]:
In [72]:
workflow = workflows[1]
res = gi.workflows.show_workflow(workflow['id'])
res
Out[72]:
In [49]:
dataset_map = {'30':{'id':'cbbbf59e8f08c98c','src':'hda'}, \
'29': {'id': '964b37715ec9bd22', 'src': 'hda' }}
outputs = gi.workflows.run_workflow(workflow['id'], dataset_map, history_id='df7a1f0c02a5b08e')#history_name='test1withhda')
Out[49]:
There are two input datasets used and one of them is 'UCSC Main on Human: knownGene (chr22:1-51304566)'.
Its id 'cbbbf59e8f08c98c' displays detailed information for the input dataset.
In [56]:
dataset = gi.datasets.show_dataset('cbbbf59e8f08c98c')
dataset
Out[56]:
In [89]:
from IPython.core.display import HTML
In [116]:
merged_htmls = ""
for output in outputs['outputs']:
dataset = gi.datasets.show_dataset(output)
#pprint.pprint(dataset)
name = dataset['name']
html = dataset['peek']
merged_htmls += "<p><b>%s</b>" % name + html + "</p>"
HTML(merged_htmls)
Out[116]:
[comment]: <> (<!---
Plans